Characteristics of Control Statements
Most control statements are compound statements that contain other statements. For example, the If statement
if today = last day of theMonth set MonthlyReport to prepareReport(currentMonth) print MonthlyReport end ifis a compound statement that contains a Set command and a Print command. Compound statements begin with one or more reserved words, such asif
in the example above, that identify the type of compound statement. The last line of a compound statement is alwaysend
, which can optionally include the word that begins the control statement.Control statements can contain other control statements. For example, this Tell statement contains the If statement of the previous example.
tell application "ReportWizard" if today = last day of theMonth set MonthlyReport to prepareReport(currentMonth) print MonthlyReport end if end tellControl statements that are contained within other control statements are sometimes called nested control statements.All control statements can be compound statements. In addition, some control statements can be written as single statements. For example, the statement
if (x > y) then return xis equivalent to
if (x > y) then return x end ifYou can use a simple statement only when you're controlling the execution of a single statement (such asreturn
x
in the previous example).